package com.wish.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.wish.dto.InterfaceInfoDto;
import com.wish.entity.SysInterfaceInfo;
import com.wish.service.ISysInterfaceInfoService;
import com.wish.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五组
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/wish/sys-interface-info")
public class SysInterfaceInfoController {

    @Autowired
    ISysInterfaceInfoService sysInterfaceInfoService;

    //机接扣管理列表展示
    @RequestMapping("interface/list")
    public ResultEntity interfacelist(InterfaceInfoDto interfaceInfoDto){

        PageInfo<SysInterfaceInfo> list = sysInterfaceInfoService.getlist(interfaceInfoDto);


        return ResultEntity.ok("200","成功",list);
    }
    //批量删除
    @RequestMapping("interface/dels")
    public boolean dels(String[] ids){
        try {
            for (String id:ids
            ) {
                QueryWrapper<SysInterfaceInfo> wrapper = new QueryWrapper<>();
                wrapper.eq("interface_no",id);
                sysInterfaceInfoService.remove(wrapper);
                System.out.print(id+"===================");
            }
            return true;
        }catch (Exception e){
            return false;
        }
    }

    //添加
    @RequestMapping("interface/add")
    public boolean add(@RequestBody  SysInterfaceInfo sysInterfaceInfo){
        try {
            sysInterfaceInfoService.save(sysInterfaceInfo);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    //修改
    @RequestMapping("interface/update")
    public boolean update(@RequestBody SysInterfaceInfo sysInterfaceInfo){
        System.out.println(sysInterfaceInfo+"=================");
        boolean b = sysInterfaceInfoService.update(sysInterfaceInfo);
        return b;
    }

    @RequestMapping("interface/getOne")
    public SysInterfaceInfo getOne(String interfaceNo){
        return sysInterfaceInfoService.getOne(interfaceNo);
    }
}
